package org.example.alibaba.provider;

import org.example.consumer.api.TestApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhigang.li
 * @date 2022/8/23
 
 
 */
@RestController
@SpringBootApplication
@ComponentScan(basePackages = {"org.example", "org.shushan"})
@EnableFeignClients(basePackages = {"org.example.consumer.api"})
public class ProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    //从nacos读取到的配置
    @Value("${shushan.test:1}")
    public String shushanTestConfig;

    //从nacos读取到的配置
    @Value("${shushan.data:1}")
    public String data;


    @Autowired
    TestApi testApi;

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("provider")
    public String  test() {
        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://shushan-consumer/consumer", String.class);
        System.out.println(data);
        return "provider" + shushanTestConfig+",consumer;"+forEntity.getBody();
    }

    @GetMapping("provider1")
    public String  test1() {
        String s = testApi.testApi();
        return "provider" + shushanTestConfig+",consumer;"+s;
    }

}
